
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.vwlConciliacionPrueba
AS
SELECT        TOP (100) PERCENT tb_ServiciosAgentes_1.idServicioAgente AS ID, dbo.tb_Organizaciones.Nombre AS Institución, dbo.tb_Organizaciones.CUISE, 
                         tb_ServiciosAgentes_1.FechaAlta, tb_ServiciosAgentes_1.FechaBaja, dbo.tb_Asignaturas.Descripcion AS Asignatura, tb_ServiciosAgentes_1.Horas, 
                         dbo.tb_SituacionRevista.Descripcion AS SituacionRevista, dbo.tb_CargosSalariales.cargo, dbo.tb_Normas.Descripcion AS NormaAlta, 
                         tb_Normas_1.Descripcion AS NormaBaja, dbo.tb_Agrupamiento.Descripcion AS Agrupamiento, tb_ServiciosAgentes_1.conciliado, 
                         tb_ServiciosAgentes_1.fechaConciliacion, dbo.tb_Agentes.Nombres, dbo.tb_Agentes.Documento, dbo.tb_CausasAltas.Descripcion AS CausaAlta, 
                         dbo.tb_CausasBajas.Descripcion AS CausaBaja, tb_ServiciosAgentes_1.Liquida,
                             (SELECT        TOP (1) dbo.tb_SituacionesLaborales.Descripcion
                               FROM            dbo.tb_SubserviciosAgentes LEFT OUTER JOIN
                                                         dbo.tb_SituacionesLaborales ON dbo.tb_SituacionesLaborales.idSituacionLaboral = dbo.tb_SubserviciosAgentes.SituacionLaboral
                               WHERE        (dbo.tb_SubserviciosAgentes.ServicioAgente = tb_ServiciosAgentes_1.idServicioAgente)
                               ORDER BY dbo.tb_SubserviciosAgentes.idSubServicio DESC) AS SituacionLaboral,
                             (SELECT        TOP (1) dbo.tb_Licencias.Descripcion
                               FROM            dbo.tb_SubserviciosAgentes AS tb_SubserviciosAgentes_2 LEFT OUTER JOIN
                                                         dbo.tb_Licencias ON dbo.tb_Licencias.idLicencia = tb_SubserviciosAgentes_2.Licencia
                               WHERE        (tb_SubserviciosAgentes_2.ServicioAgente = tb_ServiciosAgentes_1.idServicioAgente)
                               ORDER BY tb_SubserviciosAgentes_2.idSubServicio DESC) AS Licencia,
                             (SELECT        TOP (1) tb_Licencias_1.AvalLegal
                               FROM            dbo.tb_SubserviciosAgentes AS tb_SubserviciosAgentes_2 LEFT OUTER JOIN
                                                         dbo.tb_Licencias AS tb_Licencias_1 ON tb_Licencias_1.idLicencia = tb_SubserviciosAgentes_2.Licencia
                               WHERE        (tb_SubserviciosAgentes_2.ServicioAgente = tb_ServiciosAgentes_1.idServicioAgente)
                               ORDER BY tb_SubserviciosAgentes_2.idSubServicio DESC) AS AvalLegal,
                             (SELECT        TOP (1) CASE SituacionLaboral WHEN 5 THEN NULL ELSE FechaAlta END AS FechaAlta
                               FROM            dbo.tb_SubserviciosAgentes AS tb_SubserviciosAgentes_1
                               WHERE        (ServicioAgente = tb_ServiciosAgentes_1.idServicioAgente)
                               ORDER BY idSubServicio DESC) AS FechaAltaSubservicio,
                             (SELECT        TOP (1) CASE SituacionLaboral WHEN 5 THEN NULL ELSE ObservacionesSARRHH END AS ObservacionesLicencia
                               FROM            dbo.tb_SubserviciosAgentes AS tb_SubserviciosAgentes_1
                               WHERE        (ServicioAgente = tb_ServiciosAgentes_1.idServicioAgente)
                               ORDER BY idSubServicio DESC) AS ObservacionesLicencia, tb_ServiciosAgentes_1.Baja, dbo.tb_Inconsistencia.descripcion AS inconsistencia,
                             (SELECT        TOP (1) Observaciones
                               FROM            dbo.tb_Conciliacion
                               WHERE        (Servicio = tb_ServiciosAgentes_1.idServicioAgente)
                               ORDER BY idConciliacion DESC) AS Observaciones,
                             (SELECT        TOP (1) Plaza
                               FROM            dbo.tb_SubserviciosAgentes AS tb_SubserviciosAgentes_1
                               WHERE        (ServicioAgente = tb_ServiciosAgentes_1.idServicioAgente)
                               ORDER BY idSubServicio DESC) AS idPlaza,
                             (SELECT DISTINCT TOP (1) dbo.tb_Divisiones.Curso
                               FROM            dbo.tb_Plazas INNER JOIN
                                                         dbo.tb_SubserviciosAgentes AS tb_SubserviciosAgentes_4 ON dbo.tb_Plazas.idPlaza = tb_SubserviciosAgentes_4.Plaza INNER JOIN
                                                         dbo.tb_Divisiones ON dbo.tb_Plazas.Division = dbo.tb_Divisiones.idDivision RIGHT OUTER JOIN
                                                         dbo.tb_ServiciosAgentes ON tb_SubserviciosAgentes_4.ServicioAgente = dbo.tb_ServiciosAgentes.idServicioAgente
                               WHERE        (tb_SubserviciosAgentes_4.ServicioAgente = tb_ServiciosAgentes_1.idServicioAgente)) AS curso,
                             (SELECT DISTINCT TOP (1) tb_Divisiones_1.Division
                               FROM            dbo.tb_Plazas AS tb_Plazas_1 INNER JOIN
                                                         dbo.tb_SubserviciosAgentes AS tb_SubserviciosAgentes_3 ON tb_Plazas_1.idPlaza = tb_SubserviciosAgentes_3.Plaza INNER JOIN
                                                         dbo.tb_Divisiones AS tb_Divisiones_1 ON tb_Plazas_1.Division = tb_Divisiones_1.idDivision RIGHT OUTER JOIN
                                                         dbo.tb_ServiciosAgentes AS tb_ServiciosAgentes_2 ON tb_SubserviciosAgentes_3.ServicioAgente = tb_ServiciosAgentes_2.idServicioAgente
                               WHERE        (tb_SubserviciosAgentes_3.ServicioAgente = tb_ServiciosAgentes_1.idServicioAgente)) AS division, 
                         CASE dbo.tb_Bloqueos_sarrhh.ocu_cargo_bloqueado WHEN 1 THEN 1 ELSE 0 END AS ocu_cargo_bloqueado, dbo.tb_Bloqueos_sarrhh.baja_temp_fecha, 
                         dbo.tb_TiposDeNormas.Descripcion AS TipoDeNormaAlta, tb_TiposDeNormas_1.Descripcion AS TipoDeNormaBaja, 
                         tb_ServiciosAgentes_1.ObservacionesSARRHH
FROM            dbo.tb_CausasBajas RIGHT OUTER JOIN
                         dbo.tb_TiposDeNormas INNER JOIN
                         dbo.tb_Normas ON dbo.tb_TiposDeNormas.idTipoNorma = dbo.tb_Normas.TipoNorma RIGHT OUTER JOIN
                         dbo.tb_Bloqueos_sarrhh RIGHT OUTER JOIN
                         dbo.tb_ServiciosAgentes AS tb_ServiciosAgentes_1 LEFT OUTER JOIN
                         dbo.tb_Agrupamiento ON tb_ServiciosAgentes_1.Agrupamiento = dbo.tb_Agrupamiento.idAgrupamiento INNER JOIN
                         dbo.tb_SubOrganizaciones ON tb_ServiciosAgentes_1.SubOrganizacion = dbo.tb_SubOrganizaciones.idSubOrganizacion INNER JOIN
                         dbo.tb_Organizaciones ON dbo.tb_Organizaciones.idOrganizaciones = dbo.tb_SubOrganizaciones.Org AND 
                         dbo.tb_Organizaciones.idOrganizaciones = dbo.tb_SubOrganizaciones.Org INNER JOIN
                         dbo.tb_Agentes ON dbo.tb_Agentes.idAgente = tb_ServiciosAgentes_1.Agente ON 
                         dbo.tb_Bloqueos_sarrhh.ServicioAgente = tb_ServiciosAgentes_1.idServicioAgente ON 
                         dbo.tb_Normas.idNorma = tb_ServiciosAgentes_1.NormaAlta LEFT OUTER JOIN
                         dbo.tb_Normas AS tb_Normas_1 INNER JOIN
                         dbo.tb_TiposDeNormas AS tb_TiposDeNormas_1 ON tb_Normas_1.TipoNorma = tb_TiposDeNormas_1.idTipoNorma ON 
                         tb_ServiciosAgentes_1.NormaBaja = tb_Normas_1.idNorma ON dbo.tb_CausasBajas.idCausaBaja = tb_ServiciosAgentes_1.CausaBaja LEFT OUTER JOIN
                         dbo.tb_Inconsistencia ON tb_ServiciosAgentes_1.ultimaInconsistencia = dbo.tb_Inconsistencia.idInconsistencia LEFT OUTER JOIN
                         dbo.tb_CausasAltas ON tb_ServiciosAgentes_1.CausaAlta = dbo.tb_CausasAltas.idCausaAlta LEFT OUTER JOIN
                         dbo.tb_Asignaturas ON tb_ServiciosAgentes_1.Asignatura = dbo.tb_Asignaturas.idAsignatura LEFT OUTER JOIN
                         dbo.tb_SituacionRevista ON tb_ServiciosAgentes_1.SituacionRevista = dbo.tb_SituacionRevista.idSituacionRevista LEFT OUTER JOIN
                         dbo.tb_CargosSalariales ON tb_ServiciosAgentes_1.CargoSalarial = dbo.tb_CargosSalariales.idCargo
WHERE        (tb_ServiciosAgentes_1.Baja = 'N')
GO

GO
EXEC sp_addextendedproperty N'MS_DiagramPane3', N'
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
', 'SCHEMA', N'dbo', 'VIEW', N'vwlConciliacionPrueba', NULL, NULL
GO

GO
GRANT SELECT ON  [dbo].[vwlConciliacionPrueba] TO [AdministracionSagenet]
GRANT SELECT ON  [dbo].[vwlConciliacionPrueba] TO [conciliacion]
GO
GO


GO
EXEC sp_addextendedproperty N'MS_DiagramPane1', N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[20] 4[5] 2[23] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tb_Normas_1"
            Begin Extent = 
               Top = 972
               Left = 38
               Bottom = 1101
               Right = 247
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_ServiciosAgentes_1"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 135
               Right = 288
            End
            DisplayFlags = 280
            TopColumn = 39
         End
         Begin Table = "tb_Agrupamiento"
            Begin Extent = 
               Top = 138
               Left = 38
               Bottom = 233
               Right = 247
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_SubOrganizaciones"
            Begin Extent = 
               Top = 234
               Left = 38
               Bottom = 363
               Right = 260
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_Organizaciones"
            Begin Extent = 
               Top = 366
               Left = 38
               Bottom = 495
               Right = 247
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_Agentes"
            Begin Extent = 
               Top = 498
               Left = 38
               Bottom = 627
               Right = 261
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_Bloqueos_sarrhh"
            Begin Extent = 
               Top = 0
               Left = 656
               Bottom = 129
               ', 'SCHEMA', N'dbo', 'VIEW', N'vwlConciliacionPrueba', NULL, NULL
GO

GO


GO
EXEC sp_addextendedproperty N'MS_DiagramPane2', N'Right = 865
            End
            DisplayFlags = 280
            TopColumn = 3
         End
         Begin Table = "tb_CausasBajas"
            Begin Extent = 
               Top = 726
               Left = 38
               Bottom = 838
               Right = 263
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_Inconsistencia"
            Begin Extent = 
               Top = 630
               Left = 38
               Bottom = 725
               Right = 247
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_CausasAltas"
            Begin Extent = 
               Top = 840
               Left = 38
               Bottom = 969
               Right = 266
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_Normas"
            Begin Extent = 
               Top = 1104
               Left = 38
               Bottom = 1233
               Right = 247
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_Asignaturas"
            Begin Extent = 
               Top = 1236
               Left = 38
               Bottom = 1365
               Right = 266
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_SituacionRevista"
            Begin Extent = 
               Top = 1368
               Left = 38
               Bottom = 1480
               Right = 247
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_CargosSalariales"
            Begin Extent = 
               Top = 1482
               Left = 38
               Bottom = 1611
               Right = 247
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_TiposDeNormas_1"
            Begin Extent = 
               Top = 901
               Left = 413
               Bottom = 996
               Right = 622
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tb_TiposDeNormas"
            Begin Extent = 
               Top = 1006
               Left = 419
               Bottom = 1101
               Right = 628
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 34
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1725
         Width = 1500
         Width = 1500
         Width = 2910
         Width = 2430
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 2325
         Width = 2295
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 2445
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410', 'SCHEMA', N'dbo', 'VIEW', N'vwlConciliacionPrueba', NULL, NULL
GO

DECLARE @xp int
SELECT @xp=3
EXEC sp_addextendedproperty N'MS_DiagramPaneCount', @xp, 'SCHEMA', N'dbo', 'VIEW', N'vwlConciliacionPrueba', NULL, NULL
GO
